﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;

using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using YouHP.Utility;
using System.Data.SqlTypes;

namespace web.admin
{
    public partial class NewsListEdit : System.Web.UI.Page
    {
        private NewsInfoBLL newsBll = NewsInfoBLL.Instance;
        private static NewsInfo newsInfo = new NewsInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
            
        }
        protected void CancelButton_click(object sender, EventArgs e)
        {
            Response.Redirect("NewsList.aspx");
        }
        protected void InsertButton_click(object sender, EventArgs e)
        {
            NewsInfo updatedNewsInfo = validateForm(newsInfoEdit);
            bool succ = newsBll.UpdateNewsInfo(updatedNewsInfo);
            Response.Redirect("NewsList.aspx");
        }
        protected void DataBound(object sender, EventArgs e)
        {

        }
        protected void Bind()
        {
            try
            {
                int id = RequestTools.GetQueryInt("id", -1);
                if (id > 0)
                {
                    IList list = new ArrayList();
                    newsInfo = newsBll.GetNewsInfoByID(id);
                    list.Add(newsInfo);
                    this.newsInfoEdit.DataSource = list;
                    this.newsInfoEdit.DataBind();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private NewsInfo validateForm(DetailsView formViewCtl)
        {
            NewsInfo updatedNewsInfo = new NewsInfo();
            updatedNewsInfo.Id = newsInfo.Id;
            updatedNewsInfo.Title = ((TextBox)formViewCtl.FindControl("title")).Text;
            updatedNewsInfo.IsNews = true;
            updatedNewsInfo.Brif = ((TextBox)formViewCtl.FindControl("introduction")).Text;
            updatedNewsInfo.CreateTime = newsInfo.CreateTime;
            updatedNewsInfo.LastUpdateTime = DateTime.Now;

            updatedNewsInfo.Body = ((TextBox)formViewCtl.FindControl("body")).Text;
            return updatedNewsInfo;
        }
    }
}
